package teehee.Form;

import teehee.Action.SearchPageAction;
import teehee.DB.DB;

/**
 * Verifies:
 *   - Input -- No special characters, null, empty, spaces.
 * 
 * @author Eric and shub
 */
public class SearchPageForm 
{
	/**
	 * Checks if user input for search is valid
	 * @throws none
	 * @return empty "" for invalid input, closest match for valid input
	 * @param string s
	 */
	String toBeValidated;
	public SearchPageForm(String s)
	{
		toBeValidated = s;
	}
	public static boolean validate(String s) throws NullPointerException
	{
		//throw new NullPointerException();
		//Pattern p = Pattern.compile(s, "(\d");
		boolean ret = false;
		if(s == null || s == "")
			{
			return false;
			}
		//else if(s.matches(".*?\\W.*?")) //regular expression, may or may not work{
			for (int i = 0; i < s.length() ; i++) 
			{
				char c = s.charAt(i);
				if (c == 32 || (c > 47 && c < 58) || (c > 64 && c<91) || (c>96 && c<123)) 
				{
					ret = true;
				}
				else
				{
					return false;
				}
			//}
			}
			return ret;
		
	}
	
	public static DB processInput(String s)
	{
		s = SearchPageAction.convertToDbFormat(s);
		DB entry = SearchPageAction.find(s);
		return entry;
	}
}
